package com.bw.dao;

import com.bw.bean.Sku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class SkuDaoImpl implements SkuDao {


    @Override
    public List<Sku> list() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("SpringConfig.xml");
        JdbcTemplate jdbcTemplate =(JdbcTemplate) context.getBean("jdbcTemplate");
        String sql="select sku_id id,name,category_id cid,from_date fdate,price  from sku";
        List<Sku> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Sku.class));
        return query;
    }
}
